from rest_framework import serializers

from order.models import CouponModel, UserCouponModel


class CouponSerializer(serializers.ModelSerializer):
    class Meta:
        model = CouponModel
        fields = '__all__'

class UserCouponSerializer(serializers.ModelSerializer):
    coulist = serializers.SerializerMethodField(read_only=True)

    def get_coulist(self,obj):
        return {
            'id':obj.coupon.id,
            'name':obj.coupon.name,
            'condition':obj.coupon.condition,
            'price':obj.coupon.price,
            'start_time':obj.coupon.start_time,
            'end_time':obj.coupon.end_time,
        }

    class Meta:
        model = UserCouponModel
        fields = '__all__'